import * as step from '@flow-step/step-toolkit'
import process from 'process'
import runStep from './step'

runStep().then(function (exitCode: number) {
        if(exitCode == 0) {
            step.successV1('run step successfully\n')
            // empty line to clear ansi color. Otherwise the last line '{step_3-log-end}' will be colored
            // and not matched as the last line, so the log ending line '{step_3-log-end}' will appear in the log
            console.log('')
        } else {
            step.errorV1('BUILD ERROR')
            step.errorV1(process.env.BUILD_JOB_ID!)
            step.errorV1(`failed to run step，exit code: ${exitCode}`)
            process.exit(exitCode)
        }
    })
    .catch(function (err: Error) {
        step.errorV1('Unknown error')
        step.errorV1(err.message)
        step.errorV1(err.stack!)
        process.exit(-1)
    })
